package com.depth.viewer.utils
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 * 由于存在 15 秒执行限制，对于大任务，采用任务队列的方式执行
	 */
	public class TimerExecutor
	{
		private var timer:Timer;
		private var tasks:Vector.<Object>=new Vector.<Object>();
		
		public function TimerExecutor(delay:int=100)
		{
			this.timer=new Timer(delay);
			
			this.timer.addEventListener(TimerEvent.TIMER, function(event:TimerEvent):void
			{
				if (tasks.length > 0)
				{
					var task:Object=tasks.shift();
					(task.func as Function).apply(task.thisObj, task.params);
				}
			});
			
			this.timer.start();
		}
		
		public function addTask(func:Function, thisObj:Object=null, params:Array=
								null):void
		{
			this.tasks.push({func: func, thisObj: thisObj, params: params});
		}
		
	}
}